//-----------------------------------------------------------------------
// <copyright file="IDSSortDAO.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
	
using System;
using System.Data;
using MIMS.WRS.Entities;
using MyFramework;
using MyFramework.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace MIMS.WRS.Data
{	
	public class IDSSortDAO : IDSSortDAOBase
	{
		public IDSSortDAO()
		{
		}

		public virtual IDSSortCollection GetIDSSortsOnIDS()
		{            
			try
			{
				Database database = DatabaseFactory.CreateDatabase();
				DBCommandWrapper dbCommandWrapper = database.GetStoredProcCommandWrapper("spIDSSortsGetListOnIDS");
                
				IDSSortCollection iDSSortCollection = new IDSSortCollection();
				using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommandWrapper))
				{
					while (reader.Read())
					{
						IDSSort iDSSort = CreateIDSSortFromReader(reader);
						iDSSortCollection.Add(iDSSort);
					}
					reader.Close();
				}
				
				return iDSSortCollection;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new DataAccessException(SR.DataAccessGetIDSSortsException, ex);
			}
		}

		public static int GetIDSSortMaxID()
		{            
			try
			{
				Database database = DatabaseFactory.CreateDatabase();
				DBCommandWrapper dbCommandWrapper = database.GetStoredProcCommandWrapper("spIDSSortsGetMaxID");              
				return Convert.ToInt32(DataAccessHelper.ExecuteScalar(database, dbCommandWrapper));
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new DataAccessException(SR.DataAccessGetIDSSortException, ex);
			}
		}
	}
}
